from django.contrib import admin
from cetcore.models import *
from cetmusic.models import *
from cetphoto.models import *
from snippets import ReadOnlyAdminFields

class ArchiveAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
    #readonly = ('name', 'path', 'user', 'media_type','media_label',)
    list_display = ('name', 'path', 'user', 'media_label','scanning_url','writable', 'available',)
    list_filter = ('writable', 'available', )
    ordering = ('name',)
    search_fields = ('path','name',)

    fieldsets = (
       (None, {
            'fields': (
                'name', 'path', 'description', 'filegroups', 'tags',
                'generate_checksums', 'extract_metadata', 'ignore_files_below_size'
                )
       }),
       ('Scanning', {
            'classes': ('collapse',),
            'fields': ('last_update', 'scan_interval', 'scan_interval_type')
        }),
       ('Backup options', {
            'classes': ('collapse',),
            'fields': ('rsync_options', 'rsync_target', 'rsync_enabled')
        }),
       ('Misc', {
            'classes': ('collapse',),
            'fields': ('available', 'writable', 'media_label', 'filesystem')
        }),
    )

    #class Media:
    #    css = {
    #        "all": ("my_styles.css",)
    #    }
    #    js = ("my_code.js",)

    

class LogAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
    #readonly = ('name', 'path', 'user', 'media_type','media_label',)
    list_display = ('section', 'text',)
    list_filter = ('log_type','section',)
    ordering = ('log_date',)
    search_fields = ('text','section',)
    date_hierarchy = 'log_date'

class FileEntryAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
    #readonly = ('filepath', 'filename', 'filesize', 'checksum','created_datetime', 'modified_datetime', 'extension', 'extension_link')
    list_display = ('filename', 'filepath', 'human_filesize', 'url', 'archive',)
    list_filter = ('date_added', 'extension', 'authentication_required', 'mature_content', 'personal_content', 'in_the_attic','archive',)
    #ordering = ('in_the_attic', 'archive', 'filepath','filename',)
    ordering = ('in_the_attic', 'date_added', 'filename','filepath',)
    search_fields = ('filepath','filename',)
    #exclude = ('pickled_metadata',)

    fieldsets = (
       (None, {
            'fields': (
                'archive',
                'filepath',
                'filename',
                'extension',
                'filesize',
                'checksum',
                'authentication_required',
                'mature_content',
                'personal_content',
                'created_datetime',
                'modified_datetime',
                'tags',
                'in_the_attic',
                )
       }),
       #('Advanced options', {
       #     'classes': ('collapse',),
        #    'fields': ('created_datetime', 'extension_link', 'modified_datetime')
        #}),
    )

    date_hierarchy = 'created_datetime'

class ActionAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
    readonly = ('file_entry',)
    list_display = ('file_entry', 'action_type', 'argument', 'sort_order',)
    list_filter = ('action_type',)
    ordering = ('action_type','-sort_order',)
    search_fields = ('file_entry',)


class FileActivityAdmin(admin.ModelAdmin):
    list_display = ('filename', 'section', 'date_added',)
    list_filter = ('section', 'user',)
    ordering = ('-date_added','user', 'filename',)
    search_fields = ('filename',)
    date_hierarchy = 'date_added'

class SongAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
    list_display = ('title', 'artist','album', 'genre', )
    list_filter = ('genre', 'artist', )
    ordering = ('artist', 'album', 'title',)
    search_fields = ('title', 'artist', 'album',)
    date_hierarchy = 'date_added'

class PhotoAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
    list_display = ('thumbnail', 'details', 'date_of_creation', 'camera_model', 'rating',)
    list_filter = ('dateperiods', 'rating', 'year', 'month', 'day', 'camera_make', 'camera_model', 'fnumber', 'iso_speed',)
    ordering = ('date_of_creation', )
    search_fields = ('title', 'description', 'notes', 'photographer', )
    #date_hierarchy = 'date_of_creation'

admin.site.register(FilePattern)
admin.site.register(FileExtension)
admin.site.register(FileSystemType)
admin.site.register(Archive, ArchiveAdmin)
admin.site.register(FileEntry, FileEntryAdmin)
admin.site.register(WordDef)
#admin.site.register(Tag)
admin.site.register(Action, ActionAdmin)
admin.site.register(Log, LogAdmin)
admin.site.register(FileActivity, FileActivityAdmin)
admin.site.register(DatePeriod)
admin.site.register(Song, SongAdmin)
admin.site.register(Playlist)
admin.site.register(Photo, PhotoAdmin)

#class PhotoAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
#    readonly = ('file_entry','date_of_creation',)
#    list_display = ('title', 'thumbnail_url', 'year', 'month', 'day', 'date_of_creation','in_the_attic',)
#    list_filter = ('in_the_attic', 'year', 'month', 'camera_make', 'camera_model', 'fnumber', 'iso_speed', 'shutter_speed', 'aperture', 'exposure_time', 'orientation',)
#    ordering = ('in_the_attic','year','month','day','title',)
#    search_fields = ('description','title',)
#    #date_hierarchy = 'date_of_creation'
#admin.site.register(Photo, PhotoAdmin)
#admin.site.register(Category)
#admin.site.register(Project)